﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MVC_Project.Bll.Systems;
using MVC_Project.Model;
using NLog;
using NLog.Fluent;

namespace MVC_Project.UI.Areas.Apis
{
    //[ApiAuthorize]
    public class DemoController : ApiController
    {
        // GET: api/Demo
        //[ApiActionMonitor]


        /// <summary>
        /// 获取会员列表信息
        /// </summary>
        /// <returns></returns>
        public PageList<Models.Users> Get(int page,int limit,string name ="")
        {
            UsersBll bll = new UsersBll();

            
            PageList<Models.Users> re = new PageList<Models.Users>();

            int count = 0;
            var users = bll.GetUsersPage(page, limit, name, out count);

            // 将数据模型 转换成 dto 模型
            List<Models.Users> list = new List<Models.Users>();
            foreach (var u in users)
            {
                list.Add(new Models.Users()
                {
                    userID = u.userID,
                    name = u.name,
                    imgID = u.imgID,
                    path = u.Images.path,
                    lastTime = u.lastTime,
                    loginName = u.loginName,
                    sex = u.sex,
                    phone = u.phone,
                    status = u.status,
                    loginPwd = u.loginPwd,
                    roleID = u.roleID,
                    roleName = u.Roles.roleName,

                });
            }

            re.code = 0;
            re.msg = "ok";
            re.data = list;
            re.count = count;
            re.page = page;
            re.size = limit;

            return re;

        }

        // GET: api/Demo/5

        /// <summary>
        /// 获取某个会员的信息
        /// </summary>
        /// <param name="id"> 会员的ID </param>
        /// <returns> 会员的全部信息 </returns>
        public string Get(int id)
        {
            //打印一句日志 


            //io
            //

            //LoggerHelper.Debug("这是一条调试日志");
            //LoggerHelper.Info("信息内容");
            //LoggerHelper.Warn("警告");
            //LoggerHelper.Error("啊，出错了");
            //LoggerHelper.Fatal("完蛋了");

            //try
            //{
            //    int num = int.Parse("abc");
            //}
            //catch (Exception ex)
            //{
            //    LoggerHelper.Error(ex.ToString());
            //    throw;
            //}

            //int num = int.Parse("abc");

            return "value";
        }

        // POST: api/Demo
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/Demo/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/Demo/5
        public void Delete(int id)
        {
        }
    }
}
